﻿$(function(){//延迟加载
	var url='';
	var brasip='';
	var brasId='';
	var brasname='';
	var jfId='';
	var done=1;//是否编辑结束
	var crows=null;
	$('#desearch').panel({
		iconCls:'icon-search',
		collapsible:true,
		title:'机房查询',
		width:'100%',
		height:'70px'
	});
		
	$('#b1').linkbutton({
		iconCls:'icon-add',
		plain:true,
		text:'添加新设备',
		width:'150px',
		onClick:function(){
			parent.addTab('添加BRAS设备','toaddbras');
		}
	});
	$('#brassec').datagrid({
		iconCls: 'icon-save',
		singleSelect: true,
		toolbar:'#tb',
		url:'showdvadminlist',
		queryParams:{
			jfId:'',
			dvip:'',
			dvfirmId:'',
			dvmodelId:'',
			dvbelong:'bras'
		},
		title:'Bras设备列表',
		height:'650px',
		pageSize:20,
//		onDblClickRow:,
		pagination:true,
		rownumbers:true,
		columns:[[{
			field:'brasname',width:'12%',title:'设备名称'
		},{
			field:'brasip',width:'13%',title:'设备IP'
		},{
			field:'juxiang',width:'8%',title:'区局'
		},{
			field:'jfname',width:'12%',title:'设备机房'
		},{
			field:'dvfirm',width:'5%',title:'设备厂商'
		},{
			field:'modelname',width:'8%',title:'设备型号'
		},{
			field:'iprange',width:'15%',title:'IP地址段'
		},{
			field:'creatdate',width:'10%',title:'录入时间',editor:'datetimebox',
			formatter:function(value,row,index){
        		if(value!=null&&value!=''){
        			var date = new Date(value);
        			Y = date.getFullYear() + '-';
        			M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        			D = (date.getDate() < 10 ? '0'+(date.getDate()) : date.getDate()) + ' ';
        			h =(date.getHours() < 10 ? '0'+(date.getHours()) : date.getHours()) + ':';
        			m =(date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':';
        			s =(date.getSeconds()< 10 ? '0'+(date.getSeconds()) : date.getSeconds()); 
        			return Y+M+D+h+m+s;
        		}else{
        			return '';
        		}
        	}
		},{
			field:'username',width:'8%',title:'录入人'
		}]],
		onLoadSuccess:function(){
//			$('#ceshi').linkbutton({
//				width:'300px',
//				text:'上联OLT：'+$('#onusec').datagrid('getRows')[0].oltname+'('+$('#onusec').datagrid('getRows')[0].oltip+')',
//				onClick:function(){
//					var rows=$('#onusec').datagrid('getRows');
//					alert(rows[0].onuId);
//				}
//			});
		}	
	});
	
	$('#brasipsec').textbox({
		buttonText:'查询',
		buttonIcon:'icon-search',
		prompt:'brasip...',
		onClickButton:function(){
			if($(this).val()!=''){
				$('#brassec').datagrid('reload',{
					dvip:$('#brasipsec').val(),
					dvfirmId:'',
					dvmodelId:'',
					jfId:'',
					dvbelong:'bras'
				});				
			}
		}
	});
	
	$('#dvmodel').combobox({
		width:'150px',
		disabled:true,
		onChange:function(newValue,oldValue){
			if(newValue!=''){				
				$('#brassec').datagrid('reload',{
					dvip:'',
					dvfirmId:'',
					dvmodelId:newValue,
					jfId:'',
					dvbelong:'bras'
				});
			}
		}
	});
	
	$('#dvfirm').combobox({
		onChange:function(newValue,oldValue){
			if(newValue==''){				
				$('#dvmodel').combobox({
					disabled:true
				});
			}else{
				$('#dvmodel').combobox({
					//value:'请选择',
					disabled:false,
					valueField:'dvmodelId',
					textField:'modelname',
					url:"showmodelsec?dvbelong=bras&dvfirmId="+newValue,
				});
			}
		}
	});
	
	
	var pager = $('#brassec').datagrid('getPager');	// get the pager of datagrid
	pager.pagination({
		buttons:[{
			iconCls:'icon-zzjg',
			plain:false,
			text:'设备详细拓扑',
			width:'150px',
			handler:function(){
				var secrow=$('#brassec').datagrid('getSelected');
//				alert(secrow);
				if(secrow!=null){				
					brasip=secrow.brasip;
					brasname=secrow.brasname;
					brasId=secrow.brasId;
					parent.addTab(brasname+'('+brasip+')','tojxtp?dvIds=bras'+','+brasId+'&sectype=1','zzjg');
					
				}
			}
		},{
			iconCls:'icon-edit',
			text:'详细信息编辑',
			width:'150px',
			handler:function(){
				var secrow=$('#brassec').datagrid('getSelected');
				var brasname=secrow.brasname;
				brasId=secrow.brasId;
				parent.addTab(brasname,'toeditbras?brasId='+brasId);
			}
		},{
			iconCls:'icon-zzjg',
			text:'配置上联设备',
			width:'150px',
			handler:function(){
				var secrow=$('#swsec').datagrid('getSelected');
				var brasname=secrow.brasname;
				brasId=secrow.brasId;
				parent.addTab('配置上联设备','toeditparent?dvId='+brasId);
			}
		}]
	});

	$('#osec').load('showjifangsec',function(){
		$.getScript('/xasj/js/component/jifangsec.js');
		$('#juxiang').combobox({
			height:'30px'
		});
		$('#dajuxiang').combobox({
			height:'30px'
		})
		$('#jifang').combobox({
			height:'30px',
			onChange:function(newValue,oldValue){
				if(newValue==''){
					return
				}
				$('#brassec').datagrid('reload',{
					jfId:newValue,
					dvip:'',
					dvfirmId:'',
					dvmodelId:'',
					dvbelong:'bras'
				});
			}
		});
	});

});